package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.zzyl.dto.BedDto;
import com.zzyl.entity.Bed;
import com.zzyl.mapper.BedMapper;
import com.zzyl.service.BedService;
import com.zzyl.vo.BedVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BedServiceImpl implements BedService {

    @Autowired
    private BedMapper bedMapper;

    @Override
    public List<BedVo> getBedsByRoomId(Long roomId) {
        return bedMapper.getBedsByRoomId(roomId);
    }

    @Override
    public int addBed(BedDto bedDto) {
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        bed.setBedStatus(0);//默认床位状态为未入住0

        return bedMapper.addBed(bed);

    }

    @Override
    public int deleteById(Long id) {
        return bedMapper.deleteById(id);
    }

    @Override
    public BedVo searchBed(Long id) {
        Bed bed = bedMapper.searchBed(id);
        return BeanUtil.copyProperties(bed, BedVo.class);
    }

    @Override
    public BedVo updateBed(BedDto bedDto) {
        Bed bed = BeanUtil.copyProperties(bedDto, Bed.class);
        Bed bed1 = bedMapper.updateBed(bed);
        return BeanUtil.copyProperties(bed1, BedVo.class);
    }

}

